package com.bdmc.web.controller.report;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.bdmc.common.annotation.RepeatSubmit;
import com.bdmc.common.annotation.Log;
import com.bdmc.common.core.controller.BaseController;
import com.bdmc.common.core.domain.PageQuery;
import com.bdmc.common.core.domain.AjaxResult;
import com.bdmc.common.core.validate.AddGroup;
import com.bdmc.common.core.validate.EditGroup;
import com.bdmc.common.core.validate.QueryGroup;
import com.bdmc.common.enums.BusinessType;
import com.bdmc.common.utils.poi.ExcelUtil;
import com.bdmc.report.domain.vo.ReportCarTimeVo;
import com.bdmc.report.domain.bo.ReportCarTimeBo;
import com.bdmc.report.service.IReportCarTimeService;
import com.bdmc.common.core.page.TableDataInfo;


/**
 * 发动机运行时长控制器
 *
 * @author bdmc
 * @date 2022-08-09
 */
@Validated
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/report/carTime")
public class ReportCarTimeController extends BaseController {

    private final IReportCarTimeService iReportCarTimeService;

    /**
     * 查询发动机运行时长列表
     */
    @SaCheckPermission("report:carTime:list")
    @GetMapping("/list")
    public TableDataInfo<ReportCarTimeVo> list(@Validated(QueryGroup.class) ReportCarTimeBo bo, PageQuery pageQuery) {
        return iReportCarTimeService.mySelectPage(bo, pageQuery);
    }

    /**
     * 导出发动机运行时长列表
     */
    @SaCheckPermission("report:carTime:export")
    @Log(title = "发动机运行时长", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated ReportCarTimeBo bo, HttpServletResponse response) {
        List<ReportCarTimeVo> list = iReportCarTimeService.queryList(bo);
        ExcelUtil.exportExcel(list, "发动机运行时长统计", ReportCarTimeVo.class, response);
    }

    /**
     * 获取发动机运行时长详细信息
     */
    @SaCheckPermission("report:carTime:query")
    @GetMapping("/{timeId}")
    public AjaxResult<ReportCarTimeVo> getInfo(@PathVariable("timeId") Long timeId) {
        return AjaxResult.success(iReportCarTimeService.queryById(timeId));
    }

    /**
     * 新增发动机运行时长
     */
    @SaCheckPermission("report:carTime:add")
    @Log(title = "发动机运行时长", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody ReportCarTimeBo bo) {
        return toAjax(iReportCarTimeService.insertByBo(bo));
    }

    /**
     * 修改发动机运行时长
     */
    @SaCheckPermission("report:carTime:edit")
    @Log(title = "发动机运行时长", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody ReportCarTimeBo bo) {
        return toAjax(iReportCarTimeService.updateByBo(bo));
    }

    /**
     * 删除发动机运行时长
     */
    @SaCheckPermission("report:carTime:remove")
    @Log(title = "发动机运行时长" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{timeIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] timeIds) {
        return toAjax(iReportCarTimeService.deleteWithValidByIds(Arrays.asList(timeIds), true));
    }
}
